package org.hqs.login.controller;

import org.hqs.feign.pojo.Admin;
import org.hqs.feign.pojo.Doctor;
import org.hqs.feign.pojo.Nurse;
import org.hqs.feign.pojo.Patient;
import org.hqs.login.common.JsonResult;
import org.hqs.login.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/login")
public class LoginController {
    @Autowired
    public LoginService loginService;

    @PostMapping("/admin")
    public JsonResult isAdminRight(@RequestBody Admin admin) {
        if (loginService.isAdminRight(admin.getId(), admin.getPassword())) {
            return new JsonResult("200", "管理员校验成功");
        }
        return new JsonResult("400", "管理员校验失败");
    }

    @PostMapping("/nurse")
    public JsonResult isNurseRight(@RequestBody Nurse nurse) {
        if (loginService.isNurseRight(nurse.getId(), nurse.getPassword())) {
            return new JsonResult("200", "护士校验成功");
        }
        return new JsonResult("400", "护士校验失败");
    }

    @PostMapping("/doctor")
    public JsonResult isDoctorRight(@RequestBody Doctor doctor) {
        if (loginService.isDoctorRight(Long.valueOf(doctor.getId()), doctor.getPassword())) {
            return new JsonResult("200", "医生校验成功");
        }
        return new JsonResult("400", "医生校验失败");
    }

    @PostMapping("/patient")
    public JsonResult isPatientRight(@RequestBody Patient patient) {
        if (loginService.isPatientRight(Long.valueOf(patient.getId()), patient.getPassword())) {
            return new JsonResult("200", "患者校验成功");
        }
        return new JsonResult("400", "患者校验失败");
    }
}
